         import java.util.*;
import java.lang.*;
import java.io.*;
public class ArraySort{
    String [] words;
    
    public ArraySort(String args) {
        
        String line = "";
        String inFile = "";
        int wordCount = 0;
        
        try{
        BufferedReader in = new BufferedReader(new FileReader(args));
        while ((line = in.readLine()) != null){
           StringTokenizer s = new StringTokenizer(line);
           while (s.hasMoreTokens()) {
               inFile += s.nextToken() + " ";
               wordCount++;
           }
        }
        
        
        System.out.println(inFile);
        words = new String[wordCount];
        StringTokenizer next = new StringTokenizer(inFile);
        for(int i = 0; i < words.length; i++){
            String min = next.nextToken();
            int count = 1;
            for (int j = i; j > -1; j--) {
                
                if (min.compareToIgnoreCase(words[j]) > 0) {
                        String newWord = words[j];
                        words[i] = words[j];
                        min = words[j];
                        words[j] = newWord;
                        count = 1;
                }
                if (min.compareToIgnoreCase(words[j]) < 0) {
                    words[j+1] = words[j];
                }
                if (min.compareToIgnoreCase(words[j]) = 0) {
                    count++;
                }
            }
        }
            
        
        }
        
        catch(IOException e){
        System.err.println(e);
        System.exit(0);
        }
        //String temp[] = new String [words.length];
        String min = "";
        for(int i = 0; i< words.length;i++){
            min = words[i];
            //System.out.println(min);
            int count = 1;
            
            for(int j = i+1; j < words.length ; j++){
                if (min.compareToIgnoreCase(words[j]) > 0) {
                    String newWord = words[i];
                    words[i] = words[j];
                    min = words[j];
                    words[j] = newWord;
                    count = 1;
                }
                if (min.compareToIgnoreCase(words[j]) == 0) {
                    count ++;
                }
            }
           words[i] = min + " " + count;
           System.out.println(words[i]);
        }
    
    }

    public void expandArray(int oldSize){
        String temp [] = new String[oldsize+1];
        for (int i = 0; i < words.length;i++) {
            temp[i] = words[i];
        }
        words = temp;

    }
    
    public static void main(String [] args){
        if (args.length != 1) {
        
        
            System.out.println("");
            System.out.println("usage: ArraySort <inputFile> <outputFile>\n");        
            
        }
        
        ArraySort a = new ArraySort(args[0]);

    }


}

